/**
 * Created by ebalmes Oct 8, 2009 5:50:34 PM
 * 
 */
package gui.validators;

import gui.components.XField;

public class TajValidator implements IValidator
{

  @Override
  public boolean validate(Object o) {    
    XField field = (XField)o;
    if (field.getText().length() != 9) {
      addToolTip(field);
      return false;
    }
    try {
      int x = Integer.parseInt(field.getText());
      removeToolTip(field);
      return true;
  }
  catch(NumberFormatException nFE) {
    addToolTip(field);
      return false;
  }
  }
  
  private void addToolTip(XField field) {
    field.setToolTipText("The taj number should be 9 digits long!");
  }
  
  private void removeToolTip(XField field) {
    field.setToolTipText("");
  }
}
